package cn.ylg.com.addfragment.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityManager;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.Random;

import cn.ylg.com.addfragment.R;

/**
 * Created by MyPC on 2016/10/15.
 */
public class NiceFragment extends Fragment {
    public static final String TYPTE = "type";
    private int type ;
    public static NiceFragment newInstance(int type) {

        Bundle args = new Bundle();
        args.putInt(TYPTE,type);
        NiceFragment fragment = new NiceFragment();
        fragment.setArguments(args);
        return fragment;
    }

    //和数据有关的；
    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       type = (int) getArguments().get(TYPTE);
    }

    @Override
    public void onStart() {
        super.onStart();

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view =  inflater.inflate(R.layout.nicefgm_layout,container,false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {

        super.onViewCreated(view, savedInstanceState);
        Log.d("-------------",""+type);
        TextView tv = (TextView) view.findViewById(R.id.frm_tv);
        FrameLayout fl = (FrameLayout) view.findViewById(R.id.bg);
        Random rd = new Random(SystemClock.currentThreadTimeMillis());
        fl.setBackgroundColor(Color.rgb(255,rd.nextInt(256),rd.nextInt(256)));
        tv.setText(""+System.currentTimeMillis());
    }
}
